<template>
  <div>
    <h2>One</h2>
    <p>count:{{ count }}</p>
  </div>
</template>

<script>
import PubSub from "pubsub-js";
export default {
  name: "One",
  data() {
    return {
      count: 0,
    };
  },
  // 订阅一般在初始化的时候就已经完成了 未来随时发布都可以
  mounted() {
    PubSub.subscribe("changeCount", (_, num) => {
      console.log("接收到了订阅消息");
      this.count += num;
    });
  },
};
</script>

<style></style>
